package cn.wolfcode.controller;

import cn.wolfcode.domain.Strategy;
import cn.wolfcode.repository.StrategyRepository;
import cn.wolfcode.service.impl.DeepSeekService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@CrossOrigin
public class DeepSeekController {

    @Autowired
    private DeepSeekService deepSeekService;
    @Autowired
    private StrategyRepository repository;

    @RequestMapping("/chat")
    public Object chat(String question) throws IOException {

        List<Strategy> strategies = repository.search(question, 3);

        String answer = deepSeekService.askWithStrategies(question, strategies);
        Map map = new HashMap();
        map.put("answer", answer);
        map.put("strategies", strategies);
        return map;
    }


}

